package com.huifaapp.mall.adapter.adapter2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.Huishengqian.Consume;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * @desc
 * @auth Mr Wu Fan
 * Created by you on 2018/3/19.
 */

public class HuaqianAdapter extends XRecyclerView.Adapter<HuaqianAdapter.viewhoder> {
        private Context context;
    List<Consume.DataBean> data = new ArrayList<>();

    public HuaqianAdapter(Context context, List<Consume.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public viewhoder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.huaqian_item, null);
        viewhoder vh = new viewhoder(view);
        return vh;
    }
    public void setData( List<Consume.DataBean> data){
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(viewhoder holder, int position) {
        holder.tvnum.setText(data.get(position).getMoney());
        holder.tvTime.setText(data.get(position).getCreateTime());
        String type = data.get(position).getType();
        if (type.equals("jd")){
            holder.tv_shengqian_name.setText(data.get(position).getInfo());

        }else if (type.equals("yh ")){
            holder.tv_shengqian_name.setText(data.get(position).getInfo());
        }else {
            holder.tv_shengqian_name.setText(data.get(position).getInfo());
        }

        String state = data.get(position).getState();
        if (state.equals(0)){
            holder.tvCun.setText("未转存");
        }else {
            holder.tvCun.setText("已转存");
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class viewhoder extends XRecyclerView.ViewHolder{
        TextView  tvnum;
        TextView tvCun;
        TextView   tv_shengqian_name;
        TextView tvTime;
        public viewhoder(View itemView) {
            super(itemView);
            tvnum = (TextView) itemView.findViewById(R.id.tvnum);
            tvCun = (TextView) itemView.findViewById(R.id.tvCun);
            tv_shengqian_name = (TextView) itemView.findViewById(R.id.tv_shengqian_name);
            tvTime = (TextView) itemView.findViewById(R.id.tvTime);
        }
    }
}
